package edu.njust.cma.mapper;

import edu.njust.cma.pojo.SubtaskEquipment;
import edu.njust.cma.pojo.SubtaskFacilityComparisonInspect;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SubtaskFacilityComparisonInspectMapper {


    @Select("select * from subtasks_facilities_comparison_inspect where user_id=#{userId}")
    SubtaskFacilityComparisonInspect getSubtaskByUserId(Integer userId);

    @Insert("insert into subtasks_facilities_comparison_inspect(task_id,user_id, type) " +
            "values(#{taskId},#{userId},#{type})")
    void create(int taskId,int userId, int type);

    @Update("update subtasks_facilities_comparison_inspect set certification_pdf_url=#{certificationPdfUrl} where id=#{id}")
    void updateUrlById(int id, String certificationPdfUrl);

    @Update("update subtasks_facilities_comparison_inspect set status=#{status} where id=#{id} and type=#{type}")
    void updateStatus(Integer id, int status,int type);

    @Select("select status from subtasks_facilities_comparison_inspect where task_id=#{taskId} and type=#{type}")
    int getStatusByTaskIdAndType(Integer taskId, int type);


    @Select("select count(*) from subtasks_facilities_comparison_inspect where task_id=#{taskId} and type=#{type}")
    int getSubtaskCountByTaskId(Integer taskId, int type);

    @Select("select * from subtasks_facilities_comparison_inspect where task_id=#{taskId} and type=#{type}")
    SubtaskFacilityComparisonInspect getSubtaskByTaskIdAndType(Integer taskId, int type);

    @Select("select * from subtasks_facilities_comparison_inspect where user_id=#{userId} and type=#{type}")
    List<SubtaskFacilityComparisonInspect> getFacilityTaskByUserId(int userId, int type);

    @Select("select * from subtasks_facilities_comparison_inspect where user_id=#{userId} and type=#{type}")
    List<SubtaskEquipment> getFacilityTaskByUserIdAndType(int userId, int type);

    @Update("update subtasks_facilities_comparison_inspect set submission_time=#{nowTime} where id=#{id}")
    void updateTimeById(int id, String nowTime);
}